namespace OFX.Aggregator.WebScraping.Implementation.BESnet.UI.Wpf
{
	using System;
	using System.Collections.Generic;
	using System.Windows.Controls;

	using Infrastructure;

	/// <summary>
	/// Interaction logic for BESnetAccountSetupUserControl.xaml
	/// </summary>
	public partial class BESnetAccountSetupUserControl : UserControl, IStatementSourceParametersProvider
	{
		public BESnetAccountSetupUserControl() { InitializeComponent(); }

		public IList<string> DisabledFields
		{
			get
			{
				var disabledFields = new List<string>();
				if (!this.AccountNumber.IsEnabled)
					disabledFields.Add(this.AccountNumber.Name);
				if (!this.AccountUserName.IsEnabled)
					disabledFields.Add(this.AccountUserName.Name);
				if (!this.AccountPassword.IsEnabled)
					disabledFields.Add(this.AccountPassword.Name);
				return disabledFields;
			}
			set
			{
				foreach (string disabledFieldName in value)
				{
					switch (disabledFieldName)
					{
						case "AccountNumber":
							this.AccountNumber.IsEnabled = false;
							break;
						case "AccountUserName":
							this.AccountUserName.IsEnabled = false;
							break;
						case "AccountPassword":
							this.AccountPassword.IsEnabled = false;
							break;
					}
				}
			}
		}

		#region IStatementSourceParametersProvider Members

		public IDictionary<string, string> GetParameters() { return new Dictionary<string, string> {{"AccountNumber", this.AccountNumber.Text}, {"AccountUserName", this.AccountUserName.Text}, {"AccountPassword", this.AccountPassword.Password}}; }

		public void SetParameters(IDictionary<string, string> parameters)
		{
			if (parameters == null) throw new ArgumentNullException("parameters");

			this.AccountNumber.Text = parameters["AccountNumber"];
			this.AccountUserName.Text = parameters["AccountUserName"];
			this.AccountPassword.Password = parameters["AccountPassword"];
		}

		#endregion
	}
}